/*
 * DOMCharactersProxy.java
 *
 * Created on September 4, 2006, 1:05 PM
 *
 * (C) 2006 R. Alexander Milowski
 */

package org.infoset.xml.dom;

import org.infoset.xml.Attribute;
import org.infoset.xml.Text;
import org.w3c.dom.Attr;
import org.w3c.dom.DOMException;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.TypeInfo;

/**
 *
 * @author alex
 */
public class DOMAttributeProxy extends DOMNodeProxy implements Attr{
   
   /** Creates a new instance of DOMCharactersProxy */
   public DOMAttributeProxy(Attribute item,DOMDocumentProxy docProxy) {
      super(item,docProxy);
   }
   
   public short getNodeType() {
      return Node.ATTRIBUTE_NODE;
   }
   
   public String getNodeValue() {
      return getTextContent();
   }
   
   public void setNodeValue(String value) {
      setTextContent(value);
   }
   
   public void setValue(String value) {
      setTextContent(value);
   }
   
   public String getValue() {
      return getTextContent();
   }
   
   public String getName() {
      Attribute a = (Attribute)item;
      String prefix = a.getPrefix();
      return prefix.length()==0 ? a.getName().getLocalName() : prefix+":"+a.getName().getLocalName();
   }
   
   
   public String getNodeName() {
      Attribute a = (Attribute)item;
      String prefix = a.getPrefix();
      return prefix.length()==0 ? a.getName().getLocalName() : prefix+":"+a.getName().getLocalName();
   }
   
   public void setTextContent(String value) {
      Text t = (Text)item;
      t.setText(value);
   }
   
   public String getTextContent() {
      Text t = (Text)item;
      return t.getText();
   }
   
   public Node cloneNode(boolean deep) {
      return new DOMAttributeProxy((Attribute)item.copyOfItem(deep),documentProxy);
   }
   
   public boolean hasAttributes() {
      return false;
   }
   public NamedNodeMap getAttributes() {
      return null;
   }
   
   public void setPrefix(String value) {
      Attribute a = (Attribute)item;
      a.setPrefix(value);
   }
   
   public String getPrefix() {
      Attribute a = (Attribute)item;
      return a.getPrefix();
   }
   
   public boolean hasChildNodes() {
      return false;
   }
   
   public Node appendChild(Node n) {
      throw new DOMException(DOMException.NOT_SUPPORTED_ERR,"Method not supported on attributes.");
   }
   public Node removeChild(Node n) {
      throw new DOMException(DOMException.NOT_SUPPORTED_ERR,"Method not supported on attributes.");
   }
   public Node insertBefore(Node newNode,Node refChild) {
      throw new DOMException(DOMException.NOT_SUPPORTED_ERR,"Method not supported on attributes.");
   }
   public Node replaceChild(Node newNode,Node oldChild) {
      throw new DOMException(DOMException.NOT_SUPPORTED_ERR,"Method not supported on attributes.");
   }
   
   public Node getNextSibling() {
      return null;
   }
   public Node getPreviousSibling() {
      return null;
   }
   public Node getLastChild() {
      return null;
   }
   public Node getFirstChild() {
      return null;
   }
   public NodeList getChildNodes() {
      return null;
   }
   public Node getParentNode() {
      return null;
   }
   
   public boolean isId() {
      return false;
   }

   public boolean getSpecified() {
      return true;
   }

   public TypeInfo getSchemaTypeInfo() {
      return null;
   }
   
   public org.w3c.dom.Element getOwnerElement() {
      return (org.w3c.dom.Element)documentProxy.getProxy(((Attribute)item).getElement());
   }
}
